package com.lanou.dllo.mynovel.activity;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.View;
import android.widget.TabHost;


import com.lanou.dllo.mynovel.R;
import com.lanou.dllo.mynovel.fragment.FavoriteFragment;
import com.lanou.dllo.mynovel.fragment.GameFragment;
import com.lanou.dllo.mynovel.fragment.StoreFragment;
import com.lanou.dllo.mynovel.fragment.UserFragment;

import java.sql.Date;
import java.text.SimpleDateFormat;

public class MainActivity extends FragmentActivity {
    private TabHost tabHost;
    private FragmentManager manager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

//        // 时间格式化
//        SimpleDateFormat    formatter    =   new SimpleDateFormat("mm");
//        Long time  = System.currentTimeMillis();
//        Date    curDate    =   new Date(1446099012000l);//获取当前时间
//        String    str    =    formatter.format(curDate);
//        Log.i("时间", "time ====>" + str);
    }

    // 初始化数据
    private void initView() {
        tabHost = (TabHost) findViewById(android.R.id.tabhost);
        tabHost.setup();
        // 页卡1
        TabHost.TabSpec spec1 = tabHost.newTabSpec("spec1");
        View view1 = getLayoutInflater().inflate(R.layout.activity_tab_store, null);
        spec1.setIndicator(view1);
        spec1.setContent(R.id.storeView);
        tabHost.addTab(spec1);
        // 页卡2
        TabHost.TabSpec spec2 = tabHost.newTabSpec("spec2");
        View view2 = getLayoutInflater().inflate(R.layout.activity_tab_favorite, null);
        spec2.setIndicator(view2);
        spec2.setContent(R.id.favoriteView);
        tabHost.addTab(spec2);
        // 页卡3
        TabHost.TabSpec spec3 = tabHost.newTabSpec("spec3");
        View view3 = getLayoutInflater().inflate(R.layout.activity_tab_game, null);
        spec3.setIndicator(view3);
        spec3.setContent(R.id.gameView);
        tabHost.addTab(spec3);
        // 页卡4
        TabHost.TabSpec spec4 = tabHost.newTabSpec("spec4");
        View view4 = getLayoutInflater().inflate(R.layout.activity_tab_user, null);
        spec4.setIndicator(view4);
        spec4.setContent(R.id.userView);
        tabHost.addTab(spec4);

        initFragment();
    }

    // 绑定内容页卡
    private void initFragment() {
        manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();

        transaction.replace(R.id.storeView, new StoreFragment());
        transaction.replace(R.id.favoriteView, new FavoriteFragment());
        transaction.replace(R.id.gameView, new GameFragment());
        transaction.replace(R.id.userView, new UserFragment());

        transaction.commit();
    }


}
